package com.lagou.work1;

import java.io.Serializable;
import java.util.Objects;

public class Student implements Serializable {

    private static final long serialVersionUID = 1L;

    private int num;

    private String name;

    private int age;

    public Student() {
    }

    public Student(int num, String name, int age) throws AgeException, StudentNumException {
        setNum(num);
        setAge(age);
        setName(name);
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) throws StudentNumException {
        if (num>0){
            this.num = num;
        }else {
            throw new StudentNumException("学号不合理");
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) throws AgeException {
        if (age>0){
            this.age = age;
        }else {
            throw new AgeException("年龄不合理");
        }
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return num == student.num;
    }

    @Override
    public int hashCode() {
        return Objects.hash(num);
    }

    @Override
    public String toString() {
        return "Student{" +
                "num=" + num +
                ", name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
